package com.thejoyrun.retrofit.model.user;

import com.thejoyrun.retrofit.bean.User;
import com.thejoyrun.retrofit.database.DB;
import com.thejoyrun.retrofit.database.DBImpl;

import java.util.List;

/**
 * Created by kkmike999 on 2016/05/08.
 *
 * User db 操作
 */
public class UserDAO {

	DB db;

	public UserDAO() {
		db = new DBImpl();
	}

	public UserDAO(DB db) {
		this.db = db;
	}

	public User get(int uid) {
		if (db.exist(String.valueOf(uid))) {
			return db.get(String.valueOf(uid), User.class);
		}

		return new User(uid);
	}

	public void save(User user) {
		db.put(String.valueOf(user.uid), user);
	}

	public void save(List<User> users) {
		for (User user : users) {
			save(user);
		}
	}
}
